package com.javasm.service.MisMannageService.impl;


import com.javasm.dao.MisMannageDao.BuyFundDao;
import com.javasm.dao.MisMannageDao.impl.BuyFundDaoImpl;
import com.javasm.entity.MisMannageEntity.BuyFund;
import com.javasm.service.MisMannageService.BuyFundService;

import java.util.List;

/**
 * @author:JAVASM
 * @description:
 * @date:2022/5/26 11:17
 * @version:0.1
 * @since:jdk11
 */
public class BuyFundServiceImpl implements BuyFundService {

    @Override
    public Integer getFundTotalPage(Integer pageSize) {
        Integer totalPage = null;

        BuyFundDao bfd = new BuyFundDaoImpl();
        List<Integer> upProdId = bfd.getUpProdId();

        String prodIdStr = upProdId.toString();
        String substring = prodIdStr.substring(1, prodIdStr.lastIndexOf("]"));
        Integer fundTotalNum = bfd.getFundTotalNum(substring);

        totalPage = (fundTotalNum%pageSize==0)?fundTotalNum/pageSize:fundTotalNum/pageSize+1;

        return totalPage;
    }

    @Override
    public List<BuyFund> getFundByPage(Integer page, Integer pageSize, Integer typeId) {
        BuyFundDao bfd = new BuyFundDaoImpl();
        List<Integer> upProdId = bfd.getUpProdId();

        String prodIdStr = upProdId.toString();
        String substring = prodIdStr.substring(1, prodIdStr.lastIndexOf("]"));
        List<BuyFund> fundByPage = bfd.getFundByPage(page, pageSize, typeId, substring);
        return fundByPage;
    }

    @Override
    public Integer getFundTotalNum() {
        BuyFundDao bfd = new BuyFundDaoImpl();
        List<Integer> upProdId = bfd.getUpProdId();

        String prodIdStr = upProdId.toString();
        String substring = prodIdStr.substring(1, prodIdStr.lastIndexOf("]"));
        Integer fundTotalNum = bfd.getFundTotalNum(substring);
        return fundTotalNum;
    }
}
